package com.zzz.system.controller.question;

import com.zzz.common.core.controller.BaseController;
import com.zzz.common.core.domain.R;
import com.zzz.common.core.domain.TableDataInfo;
import com.zzz.system.domain.question.dto.QuestionAddDTO;
import com.zzz.system.domain.question.dto.QuestionEditDto;
import com.zzz.system.domain.question.dto.QuestionQueryDTO;
import com.zzz.system.domain.question.vo.QuestionDetailVO;
import com.zzz.system.service.question.QuestionService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @BelongsProject: oj-project
 * @BelongsPackage: com.zzz.system.controller.question
 * @Author: zhai
 * @CreateTime: 2025-10-15  20:10
 * @Description: TODO 问题管理
 * @Version: 1.0
 */
@Slf4j
@Tag(name = "系统题目管理")
@RestController
@RequestMapping("/question")
public class QuestionController extends BaseController {

    @Autowired
    private QuestionService questionService;

    /**
     * @description: 查询问题列表
     * @author: zhai
     * @date: 2025/10/19 12:48
     * @param: [questionQueryDTO]
     * @return: com.zzz.common.core.domain.TableDataInfo
     **/
    @GetMapping("/list")
    @Operation(summary = "查询题目列表", description = "查询题目列表")
    @ApiResponse(responseCode = "1000", description = "操作成功")
    @ApiResponse(responseCode = "2000", description = "操作失败")
    public TableDataInfo list(QuestionQueryDTO questionQueryDTO) {
        log.info("查询问题列表: {}", questionQueryDTO);
        return getDataTable(questionService.list(questionQueryDTO));
    }

    /**
     * @description: 添加问题
     * @author: zhai
     * @date: 2025/10/19 12:48
     * @param: [questionAddDTO]
     * @return: com.zzz.common.core.domain.R<java.lang.Void>
     **/
    @PostMapping("/add")
    @Operation(summary = "添加问题", description = "添加问题")
    @ApiResponse(responseCode = "1000", description = "操作成功")
    @ApiResponse(responseCode = "2000", description = "操作失败")
    public R<Void> add(@Validated @RequestBody QuestionAddDTO questionAddDTO) {
        log.info("添加问题: {}", questionAddDTO);
        return toR(questionService.add(questionAddDTO));
    }

    /**
     * @description: 获取问题详细信息
     * @author: zhai
     * @date: 2025/10/19 12:48
     * @param: [questionEditDto]
     * @return: com.zzz.common.core.domain.R<com.zzz.system.domain.question.vo.QuestionDetailVO>
     **/
    @GetMapping("/detail")
    @Operation(summary = "获取问题详细信息", description = "获取问题详细信息")
    @ApiResponse(responseCode = "1000", description = "操作成功")
    @ApiResponse(responseCode = "2000", description = "操作失败")
    public R<QuestionDetailVO> update(Long questionId) {
        log.info("获取问题详细信息: {}", questionId);
        return R.success(questionService.detail(questionId));
    }

    /**
     * @description: 编辑问题
     * @author: zhai
     * @date: 2025/10/19 14:27
     * @param: [questionEditDto]
     * @return: com.zzz.common.core.domain.R<java.lang.Void>
     **/
    @PutMapping("/edit")
    @Operation(summary = "编辑问题", description = "编辑问题")
    @ApiResponse(responseCode = "1000", description = "操作成功")
    @ApiResponse(responseCode = "2000", description = "操作失败")
    public R<Void> edit(@Validated @RequestBody QuestionEditDto questionEditDto) {
        log.info("编辑问题:{}", questionEditDto);
        return toR(questionService.edit(questionEditDto));
    }

    /**
     * @description: 删除问题
     * @author: zhai
     * @date: 2025/10/19 14:27
     * @param: [questionId]
     * @return: com.zzz.common.core.domain.R<java.lang.Void>
     **/
    @DeleteMapping("/delete")
    @Operation(summary = "删除问题", description = "删除问题")
    @ApiResponse(responseCode = "1000", description = "操作成功")
    @ApiResponse(responseCode = "2000", description = "操作失败")
    public R<Void> delete(Long questionId) {
        log.info("删除问题: {}", questionId);
        return toR(questionService.delete(questionId));
    }
}
